<template>
	<uni-nav-bar :title="title" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	<view v-if="content" v-html="content" class="package_sale"></view>
</template>

<script setup lang="ts">
	import { navBack } from '@/utils/navigator';
	import { ref } from 'vue';
	import { getMessageInfo, getNoticeInfo, getActivityInfo } from '@/gql/earthPushing/ability';
	import { toPublish } from '@mqtt';
	import { showLoading } from '@/utils/prompt';
	import { onLoad } from '@dcloudio/uni-app';
	//Message 系统消息Notice公告Activity活动
	const type = ref('')
	const title = ref('标题')
	const massID = ref('')
	const content = ref()
	onLoad((pearm) => {
		type.value = pearm.type
		massID.value = pearm.id
		init()
	})
	function init() {
		showLoading()
		switch (type.value) {
			case 'Notice':
				Notices()
				break;
			case 'Message':
				Messages()
				break;
			case 'Activity':
				Activitys()
				break;
		}

	}
	function Notices() {
		const payload = {
			query: getNoticeInfo,
			variables: {
				id: Number(massID.value),
			},
		};
		toPublish('ql/staff/getNoticeInfo',
			payload,
			(obj : any) => {
				const { getNoticeInfo } = obj.data;
				content.value = getNoticeInfo.content
				title.value = getNoticeInfo.title
			},
		);
	}
	function Messages() {
		const payload = {
			query: getMessageInfo,
			variables: {
				id: Number(massID.value),
			},
		};
		toPublish('ql/staff/getMessageInfo',
			payload,
			(obj : any) => {
				const { getMessageInfo } = obj.data;
				content.value = getMessageInfo.content
				title.value = getMessageInfo.title
			},
		);
	}
	function Activitys() {
		const payload = {
			query: getActivityInfo,
			variables: {
				id: Number(massID.value),
			},
		};
		toPublish('ql/staff/getActivityInfo',
			payload,
			(obj : any) => {
				const { getActivityInfo } = obj.data;
				content.value = getActivityInfo.content
				title.value = getActivityInfo.name
			},
		);
	}
</script>

<style scoped lang="less">
</style>